<template>
	<div>
		<div :class="wrapperClass">
			<div class="content-title">
				<div class="row-ac">
					<div class="flex-1"></div>
					<div class="language-celect row-ac cursor-pointer" @click="takeLanguage">
						<i class="iconfont icon-yuyan ml"></i>
						<div class=" font-s-13" style="margin-left: 0.5rem;">{{ languageType }}</div>
					</div>
				</div>
				<div class="language-nav" v-if="languageModel">
					<div style="margin-top: 1rem;">
						<div class="language-item cursor-pointer" v-for="(item,index) in languageList" :key="index"
							@click="languageSelect(item)">
							<span>{{ item.name }}</span>
						</div>
					</div>
				</div>
				<div class="flex-1 row-a-j-fc">
					<h2>{{ languageType == 'English' ? englishTitle : turkeyTitle }}</h2>
				</div>
				<div class="flex-1 row-a-j-fc">
					<p>{{ languageType == 'English' ? englishContent : turkeyContent }}</p>
				</div>
			</div>
		</div>
		<div class="w-100 row-ac-jc" style="height: 300px;" v-if="!loadingState">
			<img src="~/assets/img/loading.gif" style="width: 60px;height: 60px;" />
			<div class="font-s-2 ml-1">加载中...</div>
		</div>
		<div class="flex-1" v-else>
			<div class="gallery">
				<div v-for="(item, index) in girlsList" :key="index" class="gallery-item cursor-pointer" @click="toPerformers(item.id)">
					<img :src="item.img" alt="图片" />
					<div class="gallery-item_SubTitle">
						<span>{{ languageType == 'English' ? item.english_identity : item.turkey_identity }}</span>
					</div>
					<div class="elden-odeme" @click.stop="createOrder">
						<span>{{ languageType == 'English' ? 'Payment' : 'Ödeme' }}</span>
					</div>
					<div class="gradient-bar"></div>
					<div class="gallery-item_Content">
						<div class="gallery-item-title flex-1 row-ac-jc">
							{{ languageType == 'English' ? item.english_name : item.turkey_name }}
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
	import {
		ref,
		onMounted,
		onUnmounted,
		watch
	} from 'vue'

	const {
		post,
		get,
		put,
		remove
	} = useFetchApi();

	import {
		useRouter
	} from 'vue-router'

	import {
		useLanguage
	} from '~/composables/useLanguage'

	const { languageType, setLanguage } = useLanguage()

	const router = useRouter()
	const loadingState = ref(false)
	const wrapperClass = ref('content-wrapper')
	const englishTitle = ref('FIRE WOMEN DETERMINE YOUR SEARCH')
	const turkeyTitle = ref('ATEŞLİ KADINLAR ARAMALARINIZI BEKLİYOR')
	const englishContent = ref('Online video chat, sexy beauties, 24-hour customer service')
	const turkeyContent = ref('Çevrimiçi görüntülü sohbet, seksi güzellikler, 7/24 müşteri hizmeti')
	const languageModel = ref(false)
	const languageList = ref([{
		id: 0,
		name: 'English'
	}, {
		id: 1,
		name: 'Türkçe'
	}])
	const pageSize = ref(500);
	const currentPage = ref(1);
	const girlsList = ref([])

	onMounted(async () => {

		const savedLang = localStorage.getItem('languageType')
		if (savedLang) {
			languageType.value = savedLang
		}

		if (window.innerWidth < 768) {
			wrapperClass.value = 'w-100 py-20 content-wrapper'
		}
		await girlprofilesData()
	})

	const girlprofilesData = async () => {
		try {
			const res = await get('/api/girlprofiles/list', {
				page: currentPage.value,
				page_size: pageSize.value
			});
			if (res.code === 200) {
				girlsList.value = res.data.list
				console.log('girlsList.value', girlsList.value);
				loadingState.value = true
			} else if (res.code == 400) {
				console.log(res.msg);
			}
		} catch (error) {
			console.error('Login failed:', error);
		}
	};

	const createOrder = () => {
		router.push(`/ulink-pay`)
	};

	const toPerformers = (id) => {
		router.push(`/performer/` + id)
	}

	const takeLanguage = () => {
		languageModel.value = !languageModel.value
	}

	const languageSelect = (item) => {
		setLanguage(item.name)
		languageModel.value = false
		localStorage.setItem('languageType', item.name) // ✅ 存储到本地
	}
</script>

<style scoped>
	.content-wrapper {
		padding: 20px 0;
		background: linear-gradient(135deg, #030d26 0%, #1a2a4a 100%);
		width: 100%;
	}

	.content-title h2 {
		color: #fcffc3;
		font-size: 2rem;
		margin-bottom: 5px;
		margin-top: 0;
		padding: 0 15px;
	}

	.content-title p {
		margin: 0;
		color: red;
		padding: 0 15px;
	}

	.language-celect {
		width: 88px;
		height: 28px;
		margin-right: 20px;
		border: 1px solid #ACACAC;
		border-radius: 15px;
		color: #ACACAC;
		background-color: #1a2a4a;
	}

	.language-nav {
		width: 88px;
		border: 1px solid #ACACAC;
		position: absolute;
		top: 51px;
		right: 20px;
		background-color: #1a2a4a;
	}

	.language-item {
		margin-left: 10px;
		margin-bottom: 10px;
		color: #ACACAC;

	}

	.gallery {
		display: grid;
		gap: 6px;
		padding: 12px;
		grid-template-columns: repeat(5, 1fr);
	}

	.gallery-item {
		border: 5px solid black;
		overflow: hidden;
		box-sizing: border-box;
		position: relative;
	}

	.gallery-item img {
		width: 100%;
		height: auto;
		display: block;
		object-fit: cover;
		box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
	}

	.gallery-item_SubTitle {
		position: absolute;
		top: 8px;
		left: 8px;
		border-radius: 3px;
		background: rgba(0, 0, 0, 0.50);
		padding: 6px;
		font-size: 11px;
		line-height: 11px;
		color: #fff;
		font-weight: 500;
		text-align: left;
		z-index: 2
	}

	.gradient-bar {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 130px;
		background: linear-gradient(to bottom, rgba(47, 30, 127, 0) 0%, rgba(47, 30, 127, 1) 100%);
		z-index: 2
	}

	.gallery-item_Content {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 20px;
		z-index: 3;
		font-size: 26px;
	}

	.gallery-item-title {
		font-size: 1em;
		line-height: 1rem;
		color: #fff;
		margin-bottom: 3px;
		font-weight: bold;
		text-shadow: 0 0 6px rgba(0, 0, 0, 0.35);
	}

	/* 中等屏幕：4 张 */
	@media (max-width: 1200px) {
		.gallery {
			grid-template-columns: repeat(4, 1fr);
		}
	}

	/* 平板：3 张 */
	@media (max-width: 992px) {
		.gallery {
			grid-template-columns: repeat(3, 1fr);
		}
	}

	/* 手机：2 张 */
	@media (max-width: 768px) {
		.gallery {
			grid-template-columns: repeat(2, 1fr);
		}

		.gradient-bar {
			height: 100px;
		}
	}
</style>